/**
 * 客户资料列表返回数据实体
 */
interface ClientInfoListItemResponse {
    /**
     * 标识符
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * 资料名称
     */
    name: string;
    /**
     * 	资料类型
     */
    infoType: string;
    /**
     * 资料级别
     */
    infoLevel: string;
    /**
     * 创建时间
     */
    createTime: string;


}
/**
* 客户资料详情返回数据实体
*/
interface ClientInfoDetailResponse extends BaseResponse {
    /**
     * 企业公司编号
     */
    enterpriseCompanyId: string;
    /**
     * 资料名称
     */
    name: string;
    /**
     * 资料类别
     */
    infoType: string;
    /**
     * 资料级别
     */
    infoLevel: string;
    /**
     * 资料内容
     */
    content: string;

    attachment:Array<attachmentList>;
}

/**
 *客户资料服务 
 */
interface IClientInfoService {
    /**
     * 获取客户资料列表
     * v1.0
     * @param enterpriseId 企业公司编号
     * @param name 资料名称
     * @param infoType 资料类别
     * @param infoLevel 档案级别
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(enterpriseid: string, name: string, infotype: string, infolevel: string, skip: number, count: number): ng.IHttpPromise<ListResponse<ClientInfoListItemResponse>>;

    /**
     * 获取客户资料详细
     * v1.0
     * @param id 客户资料详细编号
     */
    getDetail(id: string): ng.IHttpPromise<ClientInfoDetailResponse>;

    /**
     * 编辑客户资料
     * v1.0
     * @param id 需要编辑的客户资料编号
     * @param enterpriseCompanyId 企业公司编号
     * @param name 资料名称
     * @param infoType 资料类别
     * @param infoLevel 资料级别
     * @param content 资料内容
     */
    edit(id: string, enterpriseCompanyId: string, name: string, infoType: string, infoLevel: string, content: string,attachment?:Array<attachmentList>): ng.IHttpPromise<BaseResponse>;
    /**
     * 添加客户资料
     * v1.0
     * @param enterpriseCompanyId 企业公司编号
     * @param name 资料名称
     * @param infoType 资料类别
     * @param infoLevel 资料级别
     * @param content 资料内容
     */
    add(enterpriseCompanyId: string, name: string, infoType: string, infoLevel: string, content: string,attachment?:Array<attachmentList>): ng.IHttpPromise<BaseResponse>;

    /**
     * 删除客户资料
     * v1.0
     * @param id 需要删除的客户资料编号
     */
    delete(id: string): ng.IHttpPromise<BaseResponse>;
}

class clientInfoService implements IClientInfoService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(enterpriseid: string, name: string, infotype: string, infolevel: string, skip: number, count: number): ng.IHttpPromise<ListResponse<ClientInfoListItemResponse>> {
        return this.http<ListResponse<ClientInfoListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("clientInfo?enterpriseid={{enterpriseid}}&name={{name}}&infotype={{infotype}}&infolevel={{infolevel}}&skip={{skip}}&count={{count}}", {
                "enterpriseid": enterpriseid,
                "name": name,
                "infotype": infotype,
                "infolevel": infolevel,
                "skip": skip,
                "count": count
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<ClientInfoDetailResponse> {
        return this.http<ClientInfoDetailResponse>({
            method: "GET",
            url: this.route.getUrl("clientInfo/{{id}}", {
                id: id
            })
        });
    }

    edit(id: string, enterpriseCompanyId: string, name: string, infoType: string, infoLevel: string, content: string,attachment?:Array<attachmentList>): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("clientInfo/{{id}}", {
                id: id
            }),
            data: {
                name: name,
                enterpriseCompanyId: enterpriseCompanyId,
                infoType: infoType,
                infoLevel: infoLevel,
                content: content,
                Attachment:attachment
            }
        });
    }

    add(enterpriseCompanyId: string, name: string, infoType: string, infoLevel: string, content: string,attachment?:Array<attachmentList>): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("clientInfo"),
            data: {
                name: name,
                enterpriseCompanyId: enterpriseCompanyId,
                infoType: infoType,
                infoLevel: infoLevel,
                content: content,
                Attachment:attachment
            }
        });
    }

    delete(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("clientInfo/{{id}}", {
                id: id
            })
        });
    }
}

angular.module("clientInfoService",[]).service("clientInfoService", ['$http', 'routeService', clientInfoService]);

